package behavior.strategy.versionOne;

import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 商场收银系统1.0
 *
 * @author huhaiqiang
 * @date 2018/11/29 11:17
 */
@Slf4j
public class market {

    private BigDecimal total = new BigDecimal("0.0");

    private void calculateTotalPrice(BigDecimal goodsPrice, BigDecimal goodsNum, String discount) {

        BigDecimal totalPrice = goodsPrice.multiply(goodsNum);
        // 打折
        total = discountPrice(totalPrice, discount);
        log.info("===============================");
        log.info("单价：" + goodsPrice + "  数量：" + goodsNum + "  合计：" + total);
        log.info("===============================");

    }

    /**
     * 打折后的价格
     *
     * @param totalPrice
     * @param discount
     * @return BigDecimal total
     */
    private BigDecimal discountPrice(BigDecimal totalPrice, String discount) {
        totalPrice = totalPrice.multiply(new BigDecimal(discount));
        return total.add(totalPrice);
    }

    /**
     *折扣选择
     *
     * @param scan
     * @return String discount
     */
    private static String getDiscount(Scanner scan) {
        int count = scan.nextInt();
        String discount = null;
        switch (count) {
            case 1:
                discount = "0.8";
            case 2:
                discount = "0.5";
            case 3:
                discount = "0.3";
            default:
        }
        return discount;
    }

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        System.out.print("请输入单价：");
        String price = scan.nextLine();
        System.out.print("请输入数量：");
        String num = scan.nextLine();
        System.out.println("请选择折扣：1、八折  2、五折  3、三折");
        String discount = getDiscount(scan);

        market market = new market();
        market.calculateTotalPrice(new BigDecimal(price), new BigDecimal(num), discount);
    }

}
